from flask import Flask, request

from common.config.configUtils import configUtils
from common.dataManager.mongoSource import mongoSource
from faceInfoManager.faceInfoServiceImpl import faceInfoServiceImpl

app = Flask(__name__, static_folder='resources/faceImg', static_url_path='/')

mongoSource.initMongoDBSource(app)

faceInfoService = faceInfoServiceImpl()


@app.route('/upFaceData', methods=['POST'])
def upFaceData():

    personId=request.form.get("personId")

    personName = request.form.get("personName")

    personDesc = request.form.get("personDesc")

    imageslist = request.files.getlist("imageslist")

    faceGroup = request.form.get("faceGroup")

    return faceInfoService.upFaceData(personId,{"personName":personName,"personDesc":personDesc},int(faceGroup),imageslist)

@app.route('/updateFaceData', methods=['POST'])
def updateFaceData():

    personId=request.form.get("personId")

    personName = request.form.get("personName")

    personDesc = request.form.get("personDesc")

    imageslist = request.files.getlist("imageslist")

    faceGroup = request.form.get("faceGroup")

    return faceInfoService.updateFaceData(personId,{"personName":personName,"personDesc":personDesc},int(faceGroup),imageslist)

@app.route('/delFaceData', methods=['POST'])
def delFaceData():

    personId=request.form.get("personId")

    faceGroup = request.form.get("faceGroup")

    return faceInfoService.delFaceData(personId,faceGroup)

@app.route('/getSimFace', methods=['POST'])
def getSimFace():

    faceImg = request.files.getlist("faceImg")[0]

    faceGroup = request.form.get("faceGroup")

    return faceInfoService.getSimFace(faceGroup,faceImg)

@app.route('/ininStarFaceData', methods=['POST'])
def ininStarFaceData():
    faceGroup = request.form.get("faceGroup")
    filePath = request.form.get("filePath")

    return faceInfoService.ininStarFaceData(faceGroup,filePath)




app.run(host=configUtils.getConfigProperties("service", "service_host"),
        port=configUtils.getConfigProperties("service", "service_ip"))
